import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

public class SuccessPanelInOrder extends FlowPanel {
    Dimension lblSize1 = new Dimension(250, 10);
    Dimension lblSize2 = new Dimension(90, 10);
    Font font = new Font("Monospaced", Font.PLAIN, 12);
    ArrayList<JComponent> components = new ArrayList<>();

    JLabel lblFood = new JLabel("红烧带鱼");

    JLabel lblFoodNum = new JLabel("10份");

    JLabel lblCost = new JLabel("价格");

    JLabel lblCostNum = new JLabel("380.0元");

    JLabel lblTime = new JLabel("送餐时间");

    JLabel lblTimeNum = new JLabel( "19时");

    JLabel lblFreight = new JLabel("送餐费");

    JLabel lblFreightNum = new JLabel( "0.0元");

    JLabel lblTotal = new JLabel("总计");

    JLabel lblTotalNum = new JLabel( "380.0元");

    JLabel lblTitle = new JLabel("订餐成功");

    {
        components.add(lblFood);
        components.add(lblFoodNum);
        components.add(lblCost);
        components.add(lblCostNum);
        components.add(lblTime);
        components.add(lblTimeNum);
        components.add(lblFreight);
        components.add(lblFreightNum);
        components.add(lblTotal);
        components.add(lblTotalNum);

        lblTitle.setFont(new Font("Monospaced", Font.BOLD, 16));
        lblTitle.setPreferredSize(new Dimension(400, 40));
        lblTitle.setHorizontalTextPosition(JLabel.CENTER);
        add(lblTitle);


        for (JComponent component: components
        ) {
            component.setFont(font);
            if (components.indexOf(component)%2==0){
                component.setPreferredSize(lblSize1);
            } else {
                component.setPreferredSize(lblSize2);
            }
            add(component);
        }
        addButton();
    }

    public SuccessPanelInOrder(FlowLayout flowLayout){
        super(flowLayout);
    }

   public void setLblFood (String food){
        lblFood.setText(food);
   }

   public void setLblFoodNum (int foodNum){
        lblFoodNum.setText(String.format("%d", foodNum) + "份");
   }

    public void setLblTimeNum (int time){
        lblTimeNum.setText(time + "时");
    }

    public void setLblFreightNum(double freightNum){
        lblFreightNum.setText(String.format("%.1f", freightNum) + "元");
    }

    public void setLblTotalNum(double totalNum){
        lblTotalNum.setText(String.format("%.1f", totalNum) + "元");
    }

    public void setLblCostNum(double costNum){
        lblCostNum.setText(String.format("%.1f", costNum) + "元");
    }
}
